package com.base.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.base.dao.GenericDao;
import com.base.exceptions.DaoException;

@Service(value="genericService")
public abstract class GenericServiceImpl<T extends Serializable> implements GenericService<T>{
	private static final long serialVersionUID = 1L;

	public abstract GenericDao<T,Serializable> getGenericDao();
	
	@Override
	public long count() throws DaoException {
		return getGenericDao().count();
	}

	@Override
	public void delete(T entity) throws DaoException {
		getGenericDao().del(entity);
	}

	@Override
	public void deleteAll() throws DaoException {
		getGenericDao().deleteAll();
	}

	@Override
	public void deleteQuery(String condition) {
		getGenericDao().deleteQuery(condition);
	}
	
	@Override
	public void deleteById(Serializable id) throws DaoException {
		getGenericDao().deleteById(id);
	}

	@Override
	public List<T> getAll() throws DaoException {
		return getGenericDao().getAll();
	}

	@Override
	public void save(T entity) throws DaoException {
		getGenericDao().add(entity);
	}

	@Override
	public void merge(T entity) throws DaoException {
		getGenericDao().merge(entity);
	}

	@Override
	public void update(T entity) throws DaoException {
		getGenericDao().set(entity);
	}

	@Override
	public T get(Serializable id) throws DaoException {
		return getGenericDao().get(id);
	}
	
	@Override
	public List<T> getAll(int firstRow, int maxResult) throws DaoException {
		return getGenericDao().getAll(firstRow, maxResult);
	}

	@Override
	public T getByCodigo(Object codigo) throws DaoException {
		return getGenericDao().getByCodigo(codigo);
	}

	@Override
	public T getUnique(String campoUnique, Object valorUnique) throws DaoException {
		return getGenericDao().getUnique(campoUnique, valorUnique);
	}

	public List<T> getByConsulta(Map<String, Object> filtros, Integer firstResult, Integer maxResults, 
			String sortField, String sortOrder, Object count) {
		return getGenericDao().getByConsulta(filtros, firstResult, maxResults, sortField, sortOrder, count);
	}

	public List<T> getByQuery(Map<String, Object> filtros) {
		return getGenericDao().getByQuery(filtros);
	}
}
